<?php 
namespace Api\Controller;
class PayController extends CommonController{
	
	protected $m;

	
	function _initialize() {
		parent::_initialize();
		$this->m = D('YgclOrder');
	}

	
	//判断班级报名人数
	public function check_number_for_baoming(){
		$orderid = I('orderid');
		$order = $this->m->where(array('id'=>$orderid))->find();
		if(!$order){
			$this->ajaxReturn(array('status'=>0,'info'=>'订单不存在'));
			exit();
		}
		$status = R('Api/Ygcl/get_baomingcheck',array('tid'=>$order['termid'],'lid'=>$order['lid']));
		if($status['status']){
			$this->ajaxReturn(array('status'=>1,'info'=>''));//人员未满，可以发起支付
		}else{
			$d = array('id'=>$orderid,'status'=>3,'update_time'=>Date('Y-m-d H:i:s'));
			$this->m->save($d);
			$this->ajaxReturn(array('status'=>0,'info'=>'报名人数已满，无法支付，订单已设为过期'));//人员已满，不能支付
		}
	}
	
	//体验的时候判断人数
	public function check_number_for_tiyan(){
		$orderid = I('orderid');
		$order = $this->m->where(array('id'=>$orderid))->find();
		if(!$order){
			$this->ajaxReturn(array('status'=>0,'info'=>'订单不存在'));
			exit();
		}
		$status = R('Api/Ygcl/check_tiyan_number',array('lid'=>$order['lid']));
		if($status){
			$this->ajaxReturn(array('status'=>1,'info'=>'可以支付'));
		}else{
			$d = array('id'=>$orderid,'status'=>3,'update_time'=>Date('Y-m-d H:i:s'));
			$this->m->save($d);
			$this->ajaxReturn(array('status'=>0,'info'=>'该班级人数已满，请选择其他的班级体验课程，订单已设为过期'));//人员已满，不能支付
		}
	}

}